import { http } from '@/utils/request'
import type { DictDataItem, DictDataParams, QueryParams } from './type'

const prefix = import.meta.env.VITE_API_SYS

// 查询字典数据列表
export function listData(query: QueryParams & Page) {
	return http.get<ResPage<DictDataItem[]>>(`${prefix}/dict/data/list`, query)
}

// 查询字典数据详细
export function getData(dictCode: string) {
	return http.get<DictDataItem>(`${prefix}/dict/data/${dictCode}`)
}

// 根据字典类型查询字典数据信息
export function getDicts(dictType: string) {
	return http.get(`${prefix}/dict/data/type/${dictType}`)
}

// 新增字典数据
export function addData(data: DictDataParams) {
	return http.post(`${prefix}/dict/data`, data)
}

// 修改字典数据
export function updateData(data: DictDataParams) {
	return http.put(`${prefix}/dict/data`, data)
}

// 删除字典数据
export function delData(dictCode: string) {
	return http.delete(`${prefix}/dict/data/${dictCode}`)
}

// 导出
export function dataExport(data: QueryParams & Page) {
	return http.postFile<ExportResponse>(`${prefix}/dict/data/export`, data, {
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		responseType: 'blob'
	})
}
